I got up early for this

I woke up at 8am today despite staying up way late last night, partially because I'd rather be a bit groggy now than mess up my sleep schedule, but also because Advent of Code.

Nvim homework

Diagnostics listing only shows problems in current file

Still unsolved.

LSP action rename doesn't save files

Still unsolved.

Scrolling without moving cursor (too much)

Finally looked it up. Ctrl-u (move up half a page) and Ctrl-d (move down half a page) seem like what I'm looking for. zz (center screen on cursor) is nice too. But actually, it's not been as much of an issue as I thought—I'm moving around perfectly fine with a couple other motions, and especially in code ]m (next method) and [m (previous method) take care of most "macro movement".

The task itself

Code

Part one is just a simple filter over the collection of games. While writing the parsing for part one, I had a sneaking suspicion I didn't need all of the cube subsets. But I still wrote it to get all of them.

Once I saw the second part, my suspicion was confirmed: I just needed the highest amount for each colour from the entire game, per game. That let me collapse down my parsing logic a lot:

input.lines().filter_map(|line| {
	let mut colors = [0, 0, 0];
	for entry in line.split(&[':', ';', ','][..]) {
		let (n, color) = entry.trim().split_once(' ')?;
		if let Some(p) = ["red", "green", "blue"].iter().position(|&c| c == color) {
			colors[p] = colors[p].max(n.parse().ok()?);
		}
	}
	Some(colors)
})

You don't need the game ID either, because that's just position + 1. With that, the code for part one becomes simpler, too, since we don't have to iterate over the subsets of cubes in each game.

Honestly, today was much simpler than yesterday.